# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=laminar
pkgver=1.2
pkgrel=2
pkgdesc="Fast and lightweight Continuous Integration server"
url="https://laminar.ohwg.net/"
license="GPL-3.0"
arch="all !armhf !armv7 !x86" # FTBFS on 32-bit arches
arch="$arch !ppc64le !s390x" # tests fail
install="$pkgname.pre-install"
makedepends="clang cmake samurai boost-dev capnproto-dev rapidjson-dev sqlite-dev gtest-dev"
subpackages="
	$pkgname-doc
	$pkgname-openrc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
_vue_ver=2.6.12
_ansi_up_ver=4.0.4
_chart_ver=2.7.2
source="https://github.com/ohwgiles/laminar/archive/$pkgver/laminar-$pkgver.tar.gz
	vue-$_vue_ver.min.js::https://cdnjs.cloudflare.com/ajax/libs/vue/$_vue_ver/vue.min.js
	ansi_up-$_ansi_up_ver.js::https://raw.githubusercontent.com/drudru/ansi_up/v$_ansi_up_ver/ansi_up.js
	Chart-$_chart_ver.min.js::https://cdnjs.cloudflare.com/ajax/libs/Chart.js/$_chart_ver/Chart.min.js
	$pkgname.initd
	no-network.patch
	laminard-location.patch
	musl.patch
	"

prepare() {
	default_prepare

	sed -i 's/^#LAMINAR/#export LAMINAR/g' etc/laminar.conf

	install -Dm644 "$srcdir"/vue-$_vue_ver.min.js build/js/vue.min.js
	install -Dm644 "$srcdir"/ansi_up-$_ansi_up_ver.js build/js/ansi_up.js
	install -Dm644 "$srcdir"/Chart-$_chart_ver.min.js build/js/Chart.min.js
}

check() {
	./build/laminar-tests
}

build() {
	CC=clang CXX=clang++ \
		cmake -G Ninja -B build \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DLAMINAR_VERSION=$pkgver \
		-DSYSTEMD_UNITDIR=/no_systemd \
		-DBUILD_TESTS=ON
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname

	# we don't use systemd
	rm -r "$pkgdir"/no_systemd
}

sha512sums="
3fc563dd735efad5fe35a4f8f8fa0b124b0113dc43578ea4c7e8415e5139a0d462a75ac88c9406336fd2c54e98cb9c27d9f268eaeeb738a304bfa19b0f05370a  laminar-1.2.tar.gz
04a6d247e71fcb12dd300b04d2768b45e1522e0f3fa636e07f11e1fe4fe4502f361f2eebe87b51e612e1a1b6a59f681c4efce4cb27a1add444763a6c430cb627  vue-2.6.12.min.js
34c8cb74f687abc77ab84c4a504a04d9b334e9224ceffd35e6e3b31f0ff1c59ee3ddb239e5d731b6839de00485d47db34f338e2943affba04a80f6ecb43eafc3  ansi_up-4.0.4.js
1aca85f35d1c3701cc08310b4f08b7620588070298425bc2d564c027a7e4f34aed07accddc859da6842e8c1402b8e30ec575e4b045b01349382eb6fe37cec365  Chart-2.7.2.min.js
efa95e471bdc4093e6f2e4d87d3577e26387a875cc163145fa20d45b4cc20bb1d4fd7645f244221d0a916c665dc8b05b69bb7968b35a426163f4fa2fdd4ec87a  laminar.initd
0423bca2dd999eaa6f1fd246bb0d69699ec1d18569e1d4d1a13e7444a9a85d406c6e8db0e1f0afde02a4efaa10c4eef2292cf60d7ba5a6e71c06ff6617cc6000  no-network.patch
cef3436e6123c2fc71cab4cb565db625cf60e8311410fd08548f140c42745de1114e950b1459011f70bbdf45c220e63db2798b1cdeb01e82df09719208ef9620  laminard-location.patch
6b532e15a9f308a7d1c51c2c346492c0e49710b813efb1cd17ca3520479ab700d844908119a44c8e3eca3fa0d3798d98bc0c572a0ea3e865c6694eda9a656b73  musl.patch
"
